package com.splic.web.controller.product;

import java.util.List;
import com.splic.common.utils.StringUtils;
import com.splic.product.domain.Channel;
import com.splic.product.domain.Product;
import com.splic.product.dto.UserFeedbackDto;
import com.splic.product.service.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.splic.common.annotation.Log;
import com.splic.common.enums.BusinessType;
import com.splic.product.domain.UserFeedback;
import com.splic.common.core.controller.BaseController;
import com.splic.common.core.domain.AjaxResult;
import com.splic.common.utils.poi.ExcelUtil;
import com.splic.common.core.page.TableDataInfo;

/**
 * 用户反馈记录Controller
 * 
 * @author singe
 * @date 2022-01-04
 */
@Controller
@RequestMapping("/product/userFeedback")
public class UserFeedbackController extends BaseController
{
    private String prefix = "product/userFeedback";

    @Autowired
    private UserFeedbackService userFeedbackServiceImpl;

    @Autowired
    private ProductService productServiceImpl;

    @Autowired
    private DeviceStatisService deviceStatisServiceImpl;

    @Autowired
    private DeviceService deviceServiceImpl;

    @Autowired
    private ChannelService channelServiceImpl;

    @RequiresPermissions("product:userFeedback:view")
    @GetMapping()
    public String userFeedback(ModelMap mmap)
    {
        List<Product> productList = productServiceImpl.selectProductList(null);
        mmap.put("productList",productList);
        List<Channel> channelList = channelServiceImpl.selectChannelList(null);
        mmap.put("channelList",channelList);
        List<String> phoneBrandList = deviceStatisServiceImpl.selectAddPhoneBrandList();
        mmap.put("phoneBrandList",phoneBrandList);
        List<String> phoneModelList = deviceStatisServiceImpl.selectAddPhoneModelList();
        mmap.put("phoneModelList",phoneModelList);
        List<String> resolvingPowerList = deviceServiceImpl.selectResolvingPowerList();
        mmap.put("resolvingPowerList",resolvingPowerList);
        List<String> androidVersionList = deviceStatisServiceImpl.selectAddAndroidVersionList();
        mmap.put("androidVersionList",androidVersionList);
        return prefix + "/list";
    }

    /**
     * 查询用户反馈记录列表
     */
    @RequiresPermissions("product:userFeedback:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserFeedback userFeedback)
    {
        startPage();
        List<UserFeedbackDto> list = userFeedbackServiceImpl.selectPageList(userFeedback);
        return getDataTable(list);
    }

    /**
     * 新增用户反馈记录
     */
    @GetMapping(value = { "/form/{id}", "/form" })
    public String form(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id)){
            mmap.put("userFeedback", userFeedbackServiceImpl.selectUserFeedbackById(id));
        }else{
            mmap.put("userFeedback", new UserFeedback());
        }
        return prefix + "/form";
    }


    /**
     * 新增保存用户反馈记录
     */
    @RequiresPermissions("product:userFeedback:edit")
    @Log(title = "用户反馈记录", businessType = BusinessType.INSERT)
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(UserFeedback userFeedback)
    {
        return toAjax(userFeedbackServiceImpl.saveOrUpdate(userFeedback));
    }

    /**
     * 删除
     */
    @RequiresPermissions("product:userFeedback:remove")
    @Log(title = "用户反馈记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id)
    {
        return toAjax(userFeedbackServiceImpl.deleteById(id));
    }


    /**
     * 导出用户反馈记录列表
     */
    @RequiresPermissions("product:userFeedback:export")
    @Log(title = "用户反馈记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserFeedback userFeedback)
    {
        List<UserFeedback> list = userFeedbackServiceImpl.selectUserFeedbackList(userFeedback);
        ExcelUtil<UserFeedback> util = new ExcelUtil<UserFeedback>(UserFeedback.class);
        return util.exportExcel(list, "用户反馈记录数据");
    }

}
